package com.geofeature;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class OpenCellLoader 
{
	public void loadXML()
	{
		URL url = null;
		try {
			url = new URL("http://www.opencellid.org/cell/getInArea?BBOX=");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		   URLConnection urlConnection = null;
		try {
			urlConnection = url.openConnection();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		   try {
			InputStream in = new BufferedInputStream(urlConnection.getInputStream());
			readXLM(in);
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		   
	}
  public void readXLM(InputStream in)
  {
	  try {
              SAXParserFactory spf = SAXParserFactory.newInstance();
              SAXParser sp = spf.newSAXParser();
              XMLReader xr = sp.getXMLReader();
   
              URL sourceUrl = new URL(
          "http://www.opencellid.org/cell/getInArea?BBOX=");
   
//	              MyXMLHandler myXMLHandler = new MyXMLHandler();
//	              xr.setContentHandler(myXMLHandler);
              xr.parse(new InputSource(sourceUrl.openStream()));
      
   
          } catch (Exception e) {
              System.out.println("XML Pasing Excpetion = " + e);
  }
  }

}
